package com.cn.wanxi.util.servlet;

import com.cn.wanxi.util.model.CompanyModel;
import com.cn.wanxi.util.model.NavModel;
import com.cn.wanxi.util.service.CompanyService;
import com.cn.wanxi.util.service.NavService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/company")
public class CompanyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * companyModel里面为空值，需要对其赋值
         * 如果直接在这里赋值，会破坏面向对象的耦合性
         * 所以需要让别人帮我们来做。
         */
        CompanyService companyService = new CompanyService();
        CompanyModel companyModel = companyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);//key，value  key代表地址  value实际值
        NavService navService = new NavService();
        List<NavModel> list = navService.getNavModelList();
        req.setAttribute("navModels", list);


//        页面转发
        req.getRequestDispatcher("/jsp/company.jsp").forward(req, resp);
    }
}
